package org.prosim.user.service;

import java.util.List;

import org.prosim.persistence.Page;
import org.prosim.persistence.PropertyFilter;
import org.prosim.user.dao.RoleDao;
import org.prosim.user.entity.Role;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

@Service
@Transactional
public class UserService {
	@Autowired
	private RoleDao roleDao;
	
	
	/**
	 * 取得所有用户,预加载用户的角色.
	 */
	@Transactional(readOnly = true)
	public List<Role> getAllRole() {
		return roleDao.getAll();
	}
	
	
	/**
	 * 使用属性过滤条件查询角色.
	 * 
	 * @param page
	 * @param filters
	 * @return
	 */
	@Transactional(readOnly = true)
	public Page<Role> searchUser(final Page<Role> page,
			final List<PropertyFilter> filters) {
		return roleDao.findPage(page, filters);
	}
	
	

	/**
	 * 获得角色信息
	 * 
	 * @param roleId
	 * @return Role
	 */
	@Transactional(readOnly = true)
	public Role getRole(Integer roleId) {
		return roleDao.get(roleId);
	}
	
	
	/**
	 * 保存角色
	 * @param role
	 */
	public void saveRole(Role role) {
		roleDao.save(role);
	}
	
	
	/**
	 * 修改角色
	 * @param role
	 */
	public void editRole(Role role) {
		
		roleDao.save(role);
	}
	
	
	/**
	 * 删除角色
	 * @param roleId
	 */
	public void deleteRole(Integer roleId) {
		roleDao.delete(roleId);
	}
	
	
	/**
	 * 批量删除角色
	 * @param roleIds
	 */
	public void batchDeleteRole(List<Integer> roleIds) {
		for (Integer roleId : roleIds) {
			roleDao.delete(roleId);
		}
	}
}
